﻿using AspectCore.Configuration;
using AspectCore.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Fall.Core.AOP;
using System;

namespace Fall.Core.Extensions
{
    /// <summary>
    /// 注入自动提交事务拦截器
    /// </summary>
    public static class AOPExtensions
    {
        /// <summary>
        /// 提供默认的拦截
        /// </summary>
        /// <param name="services"></param>
        public static void AddFallAspectCore(this IServiceCollection services)
        {
            services.ConfigureDynamicProxy(config =>
            {
                config.Interceptors.AddTyped<FallTransacationAttribute>(Predicates.ForService("*AppService"));
            });
        }
        /// <summary>
        /// 自定义拦截
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configure"></param>
        public static void AddFallAspectCore(this IServiceCollection services, Action<IAspectConfiguration> configure = null)
        {
            services.ConfigureDynamicProxy(configure);
        }
    }
}
